﻿using CfgTable;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    /// <summary>
    /// 常驻商城
    /// </summary>
    public class UIMallNormal : UIMall
    {
        #region fields
        private UIN_MallActivePanel mallActivePanel = null;//推荐页
        private UIN_MallMonthCardPanel mallMonthCardPanel = null;//月卡页
        private UIN_MallRechargePanel mallRechargePanel = null;//充值页
        private UIN_MallNormalPanel mallNormalPanel = null;//普通商城页
        private UIBaseNode curView = null;
        #endregion fields

        #region properties

        #endregion properties

        protected override void BeforeInit()
        {
            base.BeforeInit();
        }

        protected override void OnInit()
        {
            base.OnInit();
            this.mallActivePanel = this.InitChildNode<UIN_MallActivePanel>(this.ui.mallActivePanel);
            this.mallNormalPanel = this.InitChildNode<UIN_MallNormalPanel>(this.ui.mallNormalPanel);
            this.mallRechargePanel = this.InitChildNode<UIN_MallRechargePanel>(this.ui.mallRechargePanel);
            this.mallMonthCardPanel = this.InitChildNode<UIN_MallMonthCardPanel>(this.ui.mallMonthCardPanel);

            this.HideUnit();
        }

        protected override void OnShow(UIBaseData data)
        {
            this.ShowNormalView();
        }

        protected override void OnHide()
        {
            base.OnHide();
        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {
            base.AddUGUIListener();
        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {
            base.AddMsgListeners();
        }

        protected override void OnDispose()
        {
            base.OnDispose();
            this.mallActivePanel = null;
            this.mallMonthCardPanel = null;
            this.mallRechargePanel = null;
            this.mallNormalPanel = null;
            this.curView = null;
        }

        #region methonds

        private void HideUnit()
        {
            this.mallActivePanel.Hide();
            this.mallNormalPanel.Hide();
            this.mallRechargePanel.Hide();
            this.mallMonthCardPanel.Hide();
        }

        private void ShowNormalView()
        {
            this.originalType = CfgTable.MallOriginalType.Mall;
            this.ShowMainTypeView();
        }

        protected override void ShowCurrView(int mallTypeCid, bool isShowSubType)
        {
            this.curView?.Hide();
            this.curView = null;
            var cfgMallType = TableCenter.mallType.Get(mallTypeCid);
            switch ((MallNormalMainType)cfgMallType.Type)
            {
                case MallNormalMainType.MallActive:
                    this.curView = this.mallActivePanel;
                    this.mallActivePanel.Show(cfgMallType);
                    break;
                case MallNormalMainType.MonthCard:
                    this.curView = this.mallMonthCardPanel;
                    this.mallMonthCardPanel.Show(cfgMallType);
                    break;
                case MallNormalMainType.Recharge:
                    this.curView = this.mallRechargePanel;
                    this.mallRechargePanel.Show(cfgMallType);
                    break;
                case MallNormalMainType.MallNormal:
                    this.curView = this.mallNormalPanel;
                    this.mallNormalPanel.Show(cfgMallType, isShowSubType);
                    break;
                default:
                    break;
            }

            this.ShowMoneyPanelView(cfgMallType);
        }

        private void ShowMoneyPanelView(CfgMallType cfgMallType)
        {
            if (cfgMallType.OriginalType == MallOriginalType.Mall && cfgMallType.Type == (int)MallNormalMainType.MallActive)
            {
                this.moneyPanel.Hide();
                return;
            }
            this.moneyPanel.Show(MallModule.Instance.GetMallMoneyPanelItemList(cfgMallType.Id));
        }
        #endregion methonds
    }
}
